package com.system.controller;
import com.system.exception.CustomException;
import com.system.po.*;
import com.system.service.CourseService;
import com.system.service.SelectedCourseService;
import com.system.service.StudentService;
import com.system.service.TeacherService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.annotation.Resource;
import java.util.List;
/**
 * Created by Jacey on 2017/7/6.
 */
@Controller
@RequestMapping(value = "/teacher")
public class TeacherController {
	@Resource(name = "teacherServiceImpl")
	private TeacherService teacherService;
	@Resource(name = "courseServiceImpl")
	private CourseService courseService;
	@Resource(name = "selectedCourseServiceImpl")
	private SelectedCourseService selectedCourseService;
	// 显示我的课程
	@RequestMapping(value = "/showCourse")
	public String stuCourseShow(Model model) throws Exception {
		Subject subject = SecurityUtils.getSubject();
		String username = (String) subject.getPrincipal();
		List<CourseCustom> list = courseService.findByTeacherID(Integer.parseInt(username));
		model.addAttribute("courseList", list);
		return "teacher/showCourse";
	}
	// 显示成绩
	@RequestMapping(value = "/gradeCourse")
	public String gradeCourse(Integer id, Model model) throws Exception {
		if (id == null) {
			return "";
		}
		List<SelectedCourseCustom> list = selectedCourseService.findByCourseID(id);
		model.addAttribute("selectedCourseList", list);
		return "teacher/showGrade";
	}
	// 打分
	@RequestMapping(value = "/mark", method = {RequestMethod.GET})
	public String markUI(SelectedCourseCustom scc, Model model) throws Exception {
		SelectedCourseCustom selectedCourseCustom = selectedCourseService.findOne(scc);
		model.addAttribute("selectedCourse", selectedCourseCustom);
		return "teacher/mark";
	}
	// 打分
	@RequestMapping(value = "/mark", method = {RequestMethod.POST})
	public String mark(SelectedCourseCustom scc) throws Exception {
		selectedCourseService.updataOne(scc);
		return "redirect:/teacher/gradeCourse?id=" + scc.getCourseid();
	}
	//修改密码
	@RequestMapping(value = "/passwordRest")
	public String passwordRest() throws Exception {
		return "teacher/passwordRest";
	}
}
